<template>
  <div>
    <el-dropdown class="userDd">
      <div class="userDrop">
        <span class="userDrop_text">{{ userName }}<i class="el-icon-caret-bottom"></i>
        </span>
        <img src="@/assets/personal/avatar.png" alt="user"/>
      </div>
      <el-dropdown-menu solt="dropdown">
        <el-dropdown-item>
          <router-link to="/">
            <i class="el-icon-s-home"></i>首页
          </router-link>
        </el-dropdown-item>
        <el-dropdown-item>
          <router-link to="/personal">
            <i class="el-icon-s-custom"></i>个人中心
          </router-link>
        </el-dropdown-item>
        <el-dropdown-item divided>
          <a @click="logout()"><i class="el-icon-switch-button"></i>退出登录</a>
        </el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
import {mapGetters} from 'vuex'
import router from "@/router";

export default {
  computed: {
    ...mapGetters(['userName'])
  },
  methods: {
    logout() {
      this.$store.dispatch('user/_logout').then(() => {
        console.log('_logout success');
        router.push({
          path: '/login',
          query: {
            redirect: router.currentRoute.fullPath
          }
        }).then();
      });
    }
  }
}
</script>
